﻿@model Category
@{
    ViewBag.Title = "Index";
}
<h3 style="color:red;">Quản Lý Chủ Đề Sản Phẩm</h3>
    <div role="tabpanel">

        <!-- Nav tabs -->
        <ul class="nav nav-tabs" role="tablist">
            <li role="presentation" class="active"><a href="#edit" aria-controls="edit" role="tab" data-toggle="tab">Thêm Chủng Loại &nbsp;<span class="glyphicon glyphicon-home"></span></a></li>
            <li role="presentation"><a href="#list" aria-controls="list" role="tab" data-toggle="tab">Danh sách chủng loại &nbsp; <span class="glyphicon glyphicon-plus"></span></a></li>
        </ul>

        <!-- Tab panes -->
        <div class="tab-content">
            <div role="tabpanel" class="tab-pane active" id="edit">
                <h4>@Html.ValidationSummary(true)</h4>
                @using (Html.BeginForm("Insert", "Category",
    FormMethod.Post, new { enctype = "multipart/form-data" }))
                {
                    @Html.HiddenFor(c => c.Id)
                    <div class="row">
                        <div class="col-md-4">
                            <div class="form-group">
                                <div>Tên Tiếng Anh</div>
                                @Html.TextBoxFor(c => c.Name, new { @class = "form-control" })
                                @Html.ValidationMessageFor(c => c.Name)
                            </div>

                            <div class="form-group">
                                <div>Tên Tiếng Việt</div>
                                @Html.TextBoxFor(c => c.NameVN, new { @class = "form-control" })

                            </div>

                            <div class="form-group">
                                <div>Trạng Thái</div>
                                @Html.CheckBoxFor(c => c.Status)
                            </div>
                        </div>

                        <div class="col-md-4">
                            <div class="form-group">
                                <div>Parent_id</div>
                                @Html.TextBoxFor(c => c.Parent_id, new { @class = "form-control" })
                            </div>

                            <div class="form-group">
                                <div>Level</div>
                                @Html.TextBoxFor(c => c.Level, new { @class = "form-control" })
                            </div>

                            <div class="form-group">
                                <div>Link</div>
                                @Html.TextBoxFor(c => c.Link, new { @class = "form-control" })
                            </div>
                        </div>
                    </div>






                    <div class="form-group">
                        <div></div>
                        <div>
                            <button onclick="form.action = '/Admin/Category/Insert'" class="btn btn-default">Insert</button>
                            @if (Model.Id != 0)
                            {
                                <button onclick="form.action = '/Admin/Category/Update'" class="btn btn-default">Update</button>
                                <a href="/Admin/Category/Delete/@Model.Id" onclick="return Xoa();" class="btn btn-default">Delete</a>
                            }
                            <a href="/Admin/Category/Index"  class="btn btn-default">Reset</a>
                        </div>
                    </div>
                }
            </div>
            <div role="tabpanel" class="tab-pane" id="list">
                <br /><br />
                <div id="tableCategory"></div>
                <div>
                    <ul class="pager">
                        <li><a href="pageNo=0">First</a></li>
                        <li><a href="pageNo-=1">Prev</a></li>
                        <li><span id="pageNo"></span>&nbsp;<span>@ViewBag.PageCount</span></li>
                        <li><a href="pageNo+=1">Next</a></li>
                        <li><a href="pageNo=pageCount-1">Last</a></li>
                    </ul>
                </div>
            </div>
        </div>

    </div>

@section scripts{
    <script src="~/jquery-ui/jquery-ui.min.js"></script>
    <link href="~/jquery-ui/jquery-ui.min.css" rel="stylesheet" />>


    <script>
        $(function () {
            pageNo = 0;
            pageCount = @ViewBag.PageCount
            fnLoadPage();

            $("ul.pager a").click(function () {
                eval($(this).attr("href"));
                fnLoadPage();
                return false;
            });
        });

        function fnLoadPage() {
            if (pageNo < 0) {
                pageNo = pageCount - 1;
            }
            if (pageNo >= pageCount) {
                pageNo = 0;
            }
            $.ajax({
                url: "/Admin/Category/GetPage",
                data: { pageNo: pageNo },
                success: function (response) {
                    $("#tableCategory").html(response);
                }
            });
            $("#pageNo").html(pageNo + 1);
        }
    </script>

<script>
    function Xoa() {
        var ok = confirm("Có chắc chắn xóa mẫu tin có mã  không?");
        if (ok == true) {
            window.location.href = "/Admin/Category/Delete/@Model.Id";
        } else {
            return false;
        }
    }
</script>
}

